package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.Role;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIRoleStatsBox
{

	// 人物信息的宽高
	// public static int
	// ROLESTATS_BOX_WIDTH=DWGameManager.Screen_Width-DWGameManager.Screen_Width>>2;
	public static int ROLESTATS_BOX_HEIGHT = DWGameManager.Screen_Height
			- 100; //
	public static int EQUIP_LENGTH = 12;
	public static byte ROLESTATSTITLE = 1; // 标题为查看属性
	public static byte BAGTITLE = 2; // 标题为查看背包

	private Bitmap equipBoximg; // 背包物品背景
	private Bitmap roleAnimationimg;// 人物动画背景
	private Bitmap closeWindow;// 关闭窗口图标

	private DWFrame m_RoleStats_Frame; // 人物形象装备等面板
	private DWTitle m_RoleStats_Title;// 显示窗口标题
	private Role m_RoleStats_role = null; // 显示人物的信息
	private DWControl m_RoleStats_Animation; // 显示人物动画 
	private DWImageBox[] m_RoleStats_equipBox = new DWImageBox[EQUIP_LENGTH];// 装备栏
	private DWImageBox m_RoleStats_colosewidow; //关闭窗口
	private String title_str = null; // 标题内容

	public UIRoleStatsBox(byte title)
	{
		switch (title) {
			case 1:
				title_str = "查看属性";
				break;
			case 2:
				title_str = "查看背包";
				break;
		}
		equipBoximg = UIWindows.createImage("/img/newui/beibaowpg_1.gnp");// 背包物品背景
		roleAnimationimg = UIWindows.createImage("/img/newui/beibaorwg_1.gnp");// 人物动画背景
		closeWindow = UIWindows.createImage("/img/newui/beibaogban_1.gnp");// 关闭窗口图标
	}

	public UIRoleStatsBox(Role role, byte title)
	{
		m_RoleStats_role = role;
		switch (title) {
			case 1:
				title_str = "查看属性";
				break;
			case 2:
				title_str = "查看背包";
				break;
		}
		equipBoximg = UIWindows.createImage("/img/newui/beibaowpg_1.gnp");// 背包物品背景
		roleAnimationimg = UIWindows.createImage("/img/newui/beibaorwg_1.gnp");// 人物动画背景
		closeWindow = UIWindows.createImage("/img/newui/beibaogban_1.gnp");// 关闭窗口图标
		m_RoleStats_Frame = new DWFrame(ROLESTATS_BOX_HEIGHT,
				ROLESTATS_BOX_HEIGHT);
	}

	public void creatFram()
	{

		m_RoleStats_Title = new DWTitle(title_str, m_RoleStats_Frame);
		m_RoleStats_colosewidow = new DWImageBox(closeWindow);
		m_RoleStats_colosewidow.setNearAnchor(m_RoleStats_Frame, Tools.RIGHT_TOP, Tools.RIGHT_TOP);
		m_RoleStats_colosewidow.addListener(new DWListener() {

			public void OnDoubleClick()
			{
				DWControlsManager.getInstance().removeControl(m_RoleStats_Frame);
			}

			public void OnClick()
			{
				// TODO Auto-generated method stub
				DWControlsManager.getInstance().removeControl(m_RoleStats_Frame);
			}
		});

		if (m_RoleStats_role == null) {
			m_RoleStats_Animation = new DWImageBox(roleAnimationimg);
		}
		else {
			m_RoleStats_Animation = new DWAnimationBox(m_RoleStats_role);
			m_RoleStats_Animation.setBackground(roleAnimationimg, true);
		}
		m_RoleStats_Animation.setNearAnchor(m_RoleStats_Frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		for (int i = 0; i < EQUIP_LENGTH; i++) {
			m_RoleStats_equipBox[i] = new DWImageBox(equipBoximg);
			switch (i) {
				case 0:
					m_RoleStats_equipBox[i].setNearAnchor(m_RoleStats_Animation,
							Tools.RIGHT_BOTTOM, Tools.LEFT_TOP, -20, -20);
					break;
				case 1:
				case 2:
				case 3:
					m_RoleStats_equipBox[i].setNearAnchor(
							m_RoleStats_equipBox[i - 1], Tools.HCENTER_TOP,
							Tools.HCENTER_BOTTOM, 0, 14);
					break;
				case 4:
				case 5:
				case 6:
					m_RoleStats_equipBox[i].setNearAnchor(
							m_RoleStats_equipBox[i - 1], Tools.LEFT_VCENTER,
							Tools.RIGHT_VCENTER, 14, 0);
					break;
				case 7:
				case 8:
				case 9:
					m_RoleStats_equipBox[i].setNearAnchor(
							m_RoleStats_equipBox[i - 1], Tools.HCENTER_BOTTOM,
							Tools.HCENTER_TOP, 0, -14);
					break;
				case 10:
				case 11:
					m_RoleStats_equipBox[i].setNearAnchor(
							m_RoleStats_equipBox[i - 1], Tools.RIGHT_VCENTER,
							Tools.LEFT_VCENTER, -14, 0);
					break;
			}
			m_RoleStats_Frame.addControl(m_RoleStats_equipBox[i]);
		}

		m_RoleStats_Frame.addControl(m_RoleStats_Title);
		m_RoleStats_Frame.addControl(m_RoleStats_colosewidow);
		m_RoleStats_Frame.addControl(m_RoleStats_Animation);
		Tools.debugPrintln("人物信息");
	}

	public DWFrame getRoleStatsBox()
	{
//		creatFram();
		return m_RoleStats_Frame;
	}
}
